//
//  NSString+DM_SHA_1.m
//  24-加密
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "NSString+DM_SHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (DM_SHA_1)
- (NSString *)stringWithSHA_1 {
    // 1 将字符串转换为C语言的字符串
    const char *cString = [self UTF8String];
    // 2 得到字符串的长度
    CC_LONG lent = (CC_LONG)strlen(cString);
    // 3 定义一个bytes数组
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    // 4 转换成SHA1
    CC_SHA1(cString, lent, bytes);
    
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x", bytes[i]];
    }
    return finalSHA1
    ;
}
@end
